home *** CD-ROM | disk | FTP | other *** search
- /********************************/
- /* File: GetRsrcList.c */
- /* */
- /* Given the name of a file, */
- /* return a list of all the */
- /* resources in that file. The */
- /* list contains 1 line per */
- /* resource with the following */
- /* format: */
- /* */
- /* item1 == Resource Type */
- /* item2 == Resource ID */
- /* item3 == Resource name */
- /* */
- /* If the resource fork is empty*/
- /* or non-existent, return empty*/
- /* */
- /* ---------------------------- */
- /* ©1990 Donald Koscheka */
- /* All Rights Reserved */
- /********************************/
-
- #define UsingHypercard
-
- #include <MacTypes.h>
- #include <OSUtil.h>
- #include <MemoryMgr.h>
- #include <FileMgr.h>
- #include <ResourceMgr.h>
- #include <pascal.h>
- #include <string.h>
- #include <hfs.h>
- #include "HyperXCmd.h"
- #include "HyperUtils.h"
-
- #define nil 0L
-
- /*** definition of resource header ***/
- typedef struct {
- long r_data_offset;
- long r_map_offset;
- long r_data_size;
- long r_map_size;
- char r_reserved[112];
- char r_application[128];
- } resHdr, *resHdrPtr, **resHdrHand;
-
-
- /*** definition of resource map ***/
- typedef struct {
- long r_header[4]; /* duplicates first 16 bytes in header */
- long next_map;
- short f_ref;
- short attributes;
- short r_type_list;
- short r_name_list;
- } resMap, *resMapPtr, **resMapHand;
-
-
- /*** definition of type list entry ***/
- typedef struct {
- char r_type[4]; /*** this resource type ***/
- short r_count; /*** number of resources of this type ***/
- short r_ref; /*** offset from start of type list to ***/
- /*** reference list for resources of ***/
- /*** this type (not used here) ***/
- } resTyp, *resTypPtr, **resTypHand;
-
-
-
- /*** definition of resource type list ***/
- typedef struct {
- short r_count; /* 0..n */
- resTyp r_typ[]; /* array of type entries */
- } resTypeList, *resTypeListPtr, **resTypeListHand;
-
-
-
-
- /*** definition of resource reference list ***/
- typedef struct {
- short r_id;
- short r_name; /* offset from start of name list to this name */
- long r_offset; /* offset to date (hi byte == attributes */
- Handle r_handle; /* handle when resource is in memory */
- } resRef, *resRefPtr, **resRefHand;
-
-
-
-
-
- pascal void main( paramPtr )
- XCmdBlockPtr paramPtr;
- {
- resMapPtr rMap = NIL;
- resTypeListPtr rTL;
- resTypPtr rTyp;
- resRefPtr rRef;
- Handle rsrcList = NIL; /* the output */
- resHdr rHdr;
- Str31 fName; /* name of the file */
- short ref;
- OSErr err;
- long temp;
- short i,j; /* loop counters */
- Str255 str;
-
- paramPtr->returnValue = NIL; /* prepare for the worst */
- /* (but plan for the best) */
-
- if( paramPtr->params[0] ){
-
- HLock( paramPtr->params[0] );
- ZeroToPas( paramPtr, *(paramPtr->params[0]), &fName );
- HUnlock( paramPtr->params[0] );
-
- err = (short)OpenRF( &fName, -1, &ref );
-
- if( !err ) /*** Move to start of file and read header ***/
- err = SetFPos( ref, fsFromStart, 0L );
- else
- return;
-
- if( !err ){ /*** read in the resource header ***/
- temp = (long)sizeof( resHdr );
- err = FSRead( ref, &temp, &rHdr );
- }
-
- if( !err ) /*** Move to the start of the map and read it in ***/
- err = SetFPos( ref, fsFromStart, rHdr.r_map_offset );
-
- if( !err ){
- rMap = (resMapPtr)NewPtr( rHdr.r_map_size );
- err = FSRead( ref, &rHdr.r_map_size, rMap);
- }
-
- if( !err ){
- /*** this calculation doesn't seem correct ***/
- rTL = (resTypeListPtr)((long)rMap + (long)(rMap->r_type_list));
-
- /*** move to the start of the reference list ***/
- rTyp = (resTypPtr)((long)rTL + (long)sizeof( short ));
-
- /* Allocate handle for the output list */
- if( rsrcList = NewHandle( 0L ) ){
- for( i = 0; i <= rTL->r_count; i++ ){
- rRef = (resRefPtr)((long)rTL + (long)rTyp->r_ref );
- for( j = 0; j <= rTyp->r_count; j++ ){
- /*** read the reference list entry int ***/
-
- /*** add this type & id to the output list ***/
- AppendCharToHandle( rsrcList, (char)rTyp->r_type[0]);
- AppendCharToHandle( rsrcList, (char)rTyp->r_type[1]);
- AppendCharToHandle( rsrcList, (char)rTyp->r_type[2]);
- AppendCharToHandle( rsrcList, (char)rTyp->r_type[3]);
- AppendCharToHandle( rsrcList, ',');
-
- /*** convert the id to a string and add to list ***/
- NumToStr( paramPtr, (long)rRef->r_id, &str );
- pStrToField( (char *)str, '\r', rsrcList );
- rRef++;
- }/* for j = 0 to the number of resources of this type */
- rTyp++;
- }/* for i = 0 to the number of resource types */
-
- }/* if( rsrcList allocated */
-
- AppendCharToHandle( rsrcList, '\0' );
- }
-
- if( rMap )
- DisposPtr( (Ptr)rMap );
- /*** Only reach here if file was opened ***/
- err = FSClose( ref );
- }
-
- paramPtr->returnValue = rsrcList;
- }
-
-